package com.tencent.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencent.mapper.CourseDao;
import com.tencent.pojo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

@Service
public class CourseService {

    @Autowired
    CourseDao courseDao;


    public IPage getList(Course course) {
        Page page = new Page<>(course.getPageNum(),course.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();
        if(StringUtils.isNotBlank(course.getTitle())){
            queryWrapper.like("title",course.getTitle());
        }
        return  courseDao.selectPage(page,queryWrapper);
    }

    public Course getById(BigInteger id) {
      return   courseDao.selectById(id);
    }

    public List<Chapter> getPaterById(BigInteger id) {
        Course course = new Course();
        course.setId(id);
        return courseDao.getId(course);
    }

    public void save(Videos videos) {
        courseDao.sava(videos);
    }

    public void deleteCourseById(BigInteger id) {
        courseDao.deleteById(id);
    }

    public void updateCourse(Course course) {
        courseDao.updateById(course);
    }

    public List<Tager> getAlltager() {
        return courseDao.getAllTager();
    }

    public List<CourseType> getCourseType() {
        return courseDao.getCourseType();
    }

    public List<CourseType> getCourseTypeId(int tagerId) {
        return courseDao.getCourseTypeId(tagerId);
    }
}
